<?php
include('jxc_inc_head.php');
$id=$wu->request_int('id');
$tag='product';
$data=to_array_keys('Name','CatalogID','Description','Barcode','Thumb','Price');
$data['Barcode']=get_barcode();
if($id){
	$data=$db->fetch_row("select * from tproductgoods where ID=$id");	
}
if($wu->request_string("act")=='save'){
	$m=new module('tproductgoods');
	$dm->param('Name','string','名称未填写');
	$dm->param('CatalogID','int','分类未选择');
	$dm->param('Description','string','描述未填写');
	$dm->param('Barcode','string','条码无效');
	$dm->param('Price','int','价格无效');
	if($id){
		$this->dm->update($id);	
		$wu->redirect($this->dm->update($id)?'编辑成功':$this->dm->get_error(),'product_list.php?tag='.$tag);
	}else{
		$this->dm->data('ExTags','string',$tag);
		$wu->redirect($this->dm->insert()?'添加成功':$this->dm->get_error(),'product_list.php?tag='.$tag);
	}
}
?>
<div class="location"><?php echo $wu->location_links(array('商品列表'=>'product_list.php?tag='.$tag,'编辑产品'=>'#')); ?></div>
<form action="#" method="post" >
    <table>
    	<tr><td>名称</td><td><input type="text" name="Name" size="12" value="<?php echo $data['Name']; ?>" /><span class="help-block">长度不超过15个汉字.</span></td></tr>
        <tr><td>条码</td><td><input type="text" name="Barcode" size="12" value="<?php echo $data['Barcode']; ?>" /></td></tr>
        <tr><td>价格</td><td><input type="text" name="Price" size="12" value="<?php echo $data['Price']; ?>" /></td></tr>
        <tr><td>所属分类</td><td><select name="CatalogID"><?php echo $biz->get_generaltree($data['CatalogID'],'tgeneralcatalog',$tag); ?></select></td></tr>
        <tr><td>内容</td><td><textarea name="Description" cols="120" rows="15" class="editor"><?php echo $data['Description']; ?></textarea></td></tr>
        <tr><td colspan="2"><input type="submit" value="保存" /><input type="reset" class="btn" value="重置" /></td></tr>
        </table>
        <input type="hidden" name="act" value="save" />
</form>
<?php
	include('jxc_inc_foot.php');
?>